using System;
using MySql.Data.MySqlClient;


namespace DomesticBank.Models {
	public class UsersData {
		public UsersData() {
		}
		
		
		public User getUser(string email, string pass) {
			string sql = "select * from users where email = @email and pass = @pass";
			
			MySqlCommand command = new MySqlCommand(sql, Core.Instance.getConnection());
			command.Parameters.Add("@email", MySqlDbType.VarChar);
			command.Parameters.Add("@pass", MySqlDbType.VarChar);
			
			command.Parameters["@email"].Value = email;
			command.Parameters["@pass"].Value = pass;
			
			MySqlDataReader reader = command.ExecuteReader();
			
			User user = null;
			
			if(reader.HasRows) {
				reader.Read();
				user = new User();
				user.Id = (int)reader["id"];
			}
			
			reader.Close();
			Core.Instance.closeConnection();
			
			return user;
		}
	}
}